<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>本地存储</title>
	</head>
	<body>
		
	</body>
</html>
<script>
	// localStorage 是HTML5中的本地存储对象, 存储的内容没有时间限制

	// 添加数据的方式
	// key: a  value: 5
 	localStorage.a = 5;
	console.log(localStorage.a);

	localStorage["age"] = 20;
	console.log(localStorage["age"]);
	console.log(localStorage.age);

	// key: gender   value: "男"
	localStorage.setItem("gender", "男");
	console.log(localStorage.getItem("gender"));

	// 移除数据
	localStorage.removeItem("gender");

	// 本地存储的数据的个数
	console.log(localStorage.length);
	console.log(localStorage);

	// 获取对应的数据的key值, 参数为获取第几条数据, 0代表第一条数据
	// console.log(localStorage.key(1));

	// 遍历偶有数据
	for (var i = 0; i < localStorage.length; i++) {
		console.log("key = " + localStorage.key(i));
		var key = localStorage.key(i);
		console.log("value = " + localStorage[key]);
	}

	// 清除所有数据
	// localStorage.clear();
	






</script>